#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <fcntl.h>
#include <signal.h> 
#include <stdlib.h>       
#include <string.h>
#include <pthread.h>
//#include <sys/sem.h>
#include <errno.h>
#include <sys/ipc.h>
//#include <sys/msg.h>
#include <sys/timeb.h>
#include <sys/socket.h>
//#include <sys/socketvar.h>
#include <sys/select.h>
#include <sys/stat.h>
#include <arpa/inet.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <semaphore.h>
#include <string.h>
#include <termios.h>
#include <linux/input.h>
#include <semaphore.h>
#include <linux/shm.h>
#include <asm/unistd.h>
#include <sys/poll.h>

#include "common.h"

struct recvData *CreateChain(int length)
{
		int i;
		struct recvData *back = NULL;
		struct recvData *temp = NULL;
		
		for( i = 0; i < length; i++ )
		{
				if( ( temp = (struct recvData *)malloc(sizeof(struct recvData)) ) == NULL )	
				{
						return NULL;	
				}		
				
				temp->count = 0;
				temp->pNext = back;
				back = temp;
		}
		
		return temp;
}

void InsertHead(struct recvData **dst,struct recvData *src)
{
		struct recvData *temp = src;
		
		if( temp == NULL ) return;
		
		while(temp->pNext!=NULL) temp = temp->pNext;
		
		temp->pNext = *dst;
		*dst = src;
}


void InsertTail(struct recvData **dst,struct recvData *src)
{
		struct recvData *temp = *dst;
		
		if( temp == NULL )
		{
				*dst = src;
		}
		else
		{
				while(temp->pNext!=NULL) temp = temp->pNext;		
				temp->pNext = src;
		}
}

struct recvData *GetHeadChain(struct recvData **dst)
{
		struct recvData *temp = *dst;
	
		if( (*dst) != NULL )
		{
				(*dst) = (*dst)->pNext;	
				temp->pNext = NULL;	
		}	
		
		return temp;
}



